include project.mk

####################################################################
# project paths
####################################################################
PATHOBJ := obj/
PATHSRC := src/
PATHBIN := bin/
PATHLIB := lib/
PATHTMP := tmp/
PATHARDUINO = $(PATHSRC)base/

####################################################################
# project tools
####################################################################
AR := avr-ar
GCC = avr-gcc
GXX = avr-g++
COPY = avr-objcopy
DUMP = avr-objdump
DUDE = avrdude
RM = rm -rf
ifeq ($(OS), WIN)
	CLEAR = cls
else
	CLEAR = clear
endif
####################################################################
# source files to be compiled
####################################################################
SRCARDUINO = wiring.c \
	wiring_analog.c \
	wiring_digital.c \
	wiring_pulse.c \
	wiring_shift.c \
	pins_arduino.c
SRCBOT = life.c \
	port.c \
	serial.c \
	time.c \
	tacho.c \
	main.c
TARGET = bot.elf
SRC = $(SRCARDUINO:%.c=$(PATHARDUINO)%.c)
OBJBOT = $(foreach item, $(SRCBOT),$(PATHOBJ)bot_$(item:.c=.o))
OBJCORE = $(foreach item, $(SRCARDUINO),$(PATHOBJ)core_$(item:.c=.o))
OBJ = $(OBJCORE) $(OBJBOT)	

####################################################################
# gcc settings
####################################################################
COMMON = -mmcu=$(MCU)
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=16000000UL -O0 
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -MD -MP -MT $(PATHOBJ)core_$(*F).o 

# arduino-specific build params
CDEBUG = -g$(DEBUG)
CDEFS = -DF_CPU=$(F_CPU)
CINCS = -I$(ARDUINO)
OPT = s
CWARN = -Wall -Wstrict-prototypes
CSTANDARD = -std=gnu99
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
CORE_CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
ALL_CORE_CFLAGS = -mmcu=$(MCU) -I$(PATHARDUINO) $(CORE_CFLAGS)
# end of arduino-specific build params

LIMFLAGS = -Wall -DF_CPU=16000000UL -O0 $(COMMON)

ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2

LDFLAGS = $(COMMON)
LDFLAGS +=  -Wl
#LDFLAGS +=  -Wl,-Map=blink_test.map

HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature

HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings

####################################################################
# avrdude settings
####################################################################
ifeq ($(OS), WIN)
	PORT = $(COM)
else
	PORT = /dev/ttyUSB*
endif
PART = m168
CODE = flash:w:$(PATHBIN)$(TARGET:.elf=.hex)
BAUD = 19200
PROG = arduino
DUDEFLAGS = -p $(PART) -P $(PORT) -b $(BAUD) -c $(PROG) -U $(CODE)

